package com.purong.purong.activity;

import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.purong.purong.R;
import com.purong.purong.adapter.LoanPageAdapter;
import com.purong.purong.fragment.LoanFragment;

import java.util.ArrayList;

/**
 * Created by wenjiezeng on 2017/9/28.
 * 贷款
 */
public class LoanActivity extends BaseActivity{
    private ViewPager mViewPager;
    private LoanPageAdapter mAdapter;
    private TextView quickTv,bankTv;
    private ImageView quickImg,bankImg;
    private ArrayList<Fragment> fragmentList=new ArrayList<>();

    @Override
    public void initView(){
        quickTv=(TextView)findViewById(R.id.quick_load_title);
        bankTv=(TextView)findViewById(R.id.bank_loan_title);
        mViewPager=(ViewPager)findViewById(R.id.view_pager);
        quickImg=(ImageView) findViewById(R.id.quick_load_tag);
        bankImg=(ImageView) findViewById(R.id.bank_loan_tag);
//        TestFragment1 testFragment1=new TestFragment1();
//        fragmentList.add(testFragment1);
        LoanFragment testFragment2=new LoanFragment();
        fragmentList.add(testFragment2);
        mAdapter=new LoanPageAdapter(getSupportFragmentManager(),fragmentList);
        mViewPager.setAdapter(mAdapter);
        mViewPager.setOffscreenPageLimit(2);
        mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                if (position==0){
                    quickTv.setTextColor(getResources().getColor(R.color.text_dark_gray));
                    bankTv.setTextColor(getResources().getColor(R.color.text_gray));
                    quickImg.setVisibility(View.VISIBLE);
                    bankImg.setVisibility(View.INVISIBLE);
                }else if (position==1){
                    quickTv.setTextColor(getResources().getColor(R.color.text_gray));
                    bankTv.setTextColor(getResources().getColor(R.color.text_dark_gray));
                    quickImg.setVisibility(View.INVISIBLE);
                    bankImg.setVisibility(View.VISIBLE);
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    @Override
    public void initData() {

    }

    @Override
    public int getRootViewId() {
        return R.layout.activity_loan;
    }

    public void onClick(View v){
        switch (v.getId()){
            case R.id.left_back:
                this.finish();
                break;
            case R.id.quick_lay:
                mViewPager.setCurrentItem(0);
                break;
            case R.id.bank_lay:
                mViewPager.setCurrentItem(1);
                break;
        }
    }
}
